﻿using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
namespace INTEX.DataBase.Tools
{
    public partial class INTEXDBC
    {
        public void MapQVW_QORDER(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveQVW_QORDER(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet Result = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            Result = QueryQVW_QORDER(dwData);
            if (Result.Tables.Count > 0)
            {
                tbLocal = Result.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }

            MapQVW_QORDER(ref dwLocal, dwData);

            if (!flgExist)
            {
                InsertQVW_QORDER(dwData, 1);
            }
            UpdateQVW_QORDER(dwLocal);

        }
        public void InsertQVW_QORDER(DataRow dwData, int option = 1)
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1://20140501
                    or1.CommandText = "INSERT INTO QVW_QORDER  "
                        + "SELECT DISTINCT QOKORDER AS QKAUF,QOKNEUD AS QNDATE, SUBSTR(QOKNEUD,1,4) AS QNYEAR, SUBSTR(QOKNEUD,5,2) AS QNMONTH, SUBSTR(QOKNEUD,7,2) AS QNDAY, 'Q'||CEIL(TO_NUMBER(SUBSTR(QOKNEUD,5,2))/3) AS QNQUARTER, QOKERLDAT AS QFDATE, SUBSTR(QOKERLDAT,1,4) AS QFYEAR,  SUBSTR(QOKERLDAT,5,2) AS QFMONTH,SUBSTR(QOKERLDAT,7,2) AS QFDAY,QOKPNRKRS||QOKPLFDNR AS QPLAN,QOKDYNTAB, QOKPRSFE,QOKPREINHT,QOKARTST AS ARTST,QOKART AS PART,QOKVAR AS PVAR,QOKFARBE AS PCOLOR,QOKDESS AS PDESS,QOKCOLORIT AS PDCWY,QOKBESCHICH AS PFINISH,QOKGROE AS PSIZE,QOKAUFTYP AS AUFTYP,QOKAUFTYP||QOKAUFKRS||QOKAUFLFD AS KAUF,QOKAUFTYP||QOKAUFKRS||QOKAUFLFD||QOKAUFPOS AS PAUF,QOKAUFKRS  AS PKRS,QOKAUFLFD AS PLFD,QOKAUFPOS AS PPOS,QOKAFOLGE AS PFSTEP,QOKMRESULT AS RESULT,QOKTYPE "
                        + " FROM QORDER    WHERE QOKMANDANT=:MANDANT ";
                    or1.Parameters.Add("MANDANT", OracleType.NVarChar).Value = dwData["MANDANT"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        }
        public void DeleteQVW_QORDER(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM QVW_QORDER X  ";
          
                    break; 
        
                default:
                    break;
            }
            Connect2Proxy(or1);
        }
        public DataSet QueryQVW_QORDER(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "SELECT * FROM QVW_QORDER  "; ;
  
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "QVW_QORDER";
            Return = Result;
            return Return;
        }
        public void UpdateQVW_QORDER(DataRow dwData, int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
              
                    break;
            }
            Connect2Proxy(or1);
        }
    }
}
